import app.data as data
from app.models import RecipeDBSchema, RecipeSchema


async def create(recipe: RecipeSchema) -> int:
    return await data.create(recipe)


async def get(recipe_id: int, increase_counter: bool = False):
    recipe = await data.get(recipe_id)

    if increase_counter:
        await data.update_view_count(recipe_id, recipe.view_count + 1)

    return recipe


async def get_all() -> list[RecipeDBSchema]:
    return await data.get_all()


async def update(recipe_id: int, recipe: RecipeSchema):
    return await data.update(recipe_id, recipe)


async def delete(recipe_id: int) -> RecipeDBSchema | None:
    return await data.delete(recipe_id)
